import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

import department from './modules/department';
import user from './modules/user';
import catalogue from "./modules/catalogue";
export default new Vuex.Store({
  state: {
    user:{
      id: window.sessionStorage.getItem('user'||'[]') == null ? '' : JSON.parse(window.sessionStorage.getItem('user'||'[]')).id,
      type: window.sessionStorage.getItem('user'||'[]') == null ? '' : JSON.parse(window.sessionStorage.getItem('user'||'[]')).type,
      name: window.sessionStorage.getItem('user'||'[]') == null ? '' : JSON.parse(window.sessionStorage.getItem('user'||'[]')).name,
      avatar: window.sessionStorage.getItem('user'||'[]') == null ? '' : JSON.parse(window.sessionStorage.getItem('user'||'[]')).avatar,
      nickname: window.sessionStorage.getItem('user'||'[]') == null ? '' : JSON.parse(window.sessionStorage.getItem('user'||'[]')).nickname
    },
    routes:[]
  },
  mutations: {
    initMenu(state,menus){
      state.routes = menus
    },
    login(state,user){
      state.user = user
      window.sessionStorage.setItem('user',JSON.stringify(user))
    },
    logout(state){
      window.sessionStorage.removeItem('user')
      window.sessionStorage.clear(); 
      state.routes=[]
    }
  },
  actions: {
  },
  modules: {
    department,
    user,
    catalogue
  }
})
